import socket

from util.DBHelper import DBHelper

#查询相机列表
def queryCarmera():
    dbhelper = DBHelper()
    hostname = socket.gethostname()
    print(hostname)
    hostname = "ai-process-32"
    sql = "select camera.*, class.name as class_name, kindergarten.name as kindergarten_name, class.kindergarten_id \
                    from aiparents.camera, aiparents.class, aiparents.kindergarten where camera.class_id = class.id and \
                    class.kindergarten_id = kindergarten.id and process_node='" + hostname + "'"
    # dbhelper.execute(sql,None)
    data = dbhelper.fetchall(sql)
    dbhelper.close()
    return data

def queryCarmeraByClassId(classIds):
    data = []
    dbhelper = DBHelper()
    sql = "select * from aiparents.camera_summary where class_id = %s"
    for id in classIds:
        d = dbhelper.fetchall(sql, (str(id)))
        data.append(d)
    dbhelper.close()
    return data
def queryClassById(classIds):
    classList = []
    dbhelper = DBHelper()
    sql = "SELECT kindergarten.NAME AS kindergarten_name,class.NAME AS NAME,class.type AS type,count(child.id) AS child_count,count(child.face_image) AS face_image_count,class.kindergarten_id AS kindergarten_id,class.id AS id FROM class LEFT JOIN child ON child.class_id=class.id JOIN kindergarten ON class.kindergarten_id=kindergarten.id WHERE class.id= %s"
    for id in classIds:
        d = dbhelper.fetchall(sql, (str(id)))
        classList.append(d)

    dbhelper.close()
    return classList